package boddaert.philippe.cashGame;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.transform.TransformerException;

import org.apache.log4j.Logger;

import boddaert.philippe.cashGame.comparator.GameAnalysisReport;
import boddaert.philippe.cashGame.comparator.GameAnalyzer;
import boddaert.philippe.cashGame.io.InvalidFormatException;
import boddaert.philippe.cashGame.io.in.GameImporter;
import boddaert.philippe.cashGame.io.in.XmlReader;
import boddaert.philippe.cashGame.io.out.GameAnalysisReportExporter;
import boddaert.philippe.cashGame.io.out.XmlGameExporter;
import boddaert.philippe.cashGame.io.out.XmlSiteExporter;
import boddaert.philippe.cashGame.io.out.XmlWriter;
import boddaert.philippe.cashGame.merge.GameMerger;
import boddaert.philippe.cashGame.site.ParsedSite;
import boddaert.philippe.cashGame.site.deuxfoismoincher.WebPageParser;

public class cashGame {

	private static final String EXPORT_DIRECTORY = "/Users/obiwan/Desktop/export";
	
	private final static Logger logger = Logger.getLogger(WebPageParser.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) throws TransformerException {

		try {

//			 logger.info("getting site 2xmoinscher");
//			 ParsedSite site2xmoinscher =
//			 boddaert.philippe.cashGame.site.deuxfoismoincher.WebSiteGetter
//			 .getSite();
//			 
//			 logger.info("Exporting site");
//			 XmlWriter.write(SiteExporter.export(site2xmoinscher), new File(
//			 EXPORT_DIRECTORY + "/2xmoinscher.xml"));
			 
			 logger.info("getting site priceminister");
			 ParsedSite sitePriceMinister =
			 boddaert.philippe.cashGame.site.priceminister.WebSiteGetter
			 .getSite();
			 
			 XmlWriter.write(XmlSiteExporter.export(sitePriceMinister), new File(
			 EXPORT_DIRECTORY + "/priceminister.xml"));
			 
//			 logger.info("getting site splitgames");
//			 ParsedSite siteSplitGames = boddaert.philippe.cashGame.site.splitgames.WebSiteGetter
//			 .getSite();
//									
//			 XmlWriter.write(SiteExporter.export(siteSplitGames), new File(
//			 EXPORT_DIRECTORY + "/splitgames.xml"));
									

									 


			List<Game> site2xmoinscher = GameImporter.get(XmlReader
					.read(new File(EXPORT_DIRECTORY +
							"/2xmoinscher.xml")));
//			List<Game> sitePriceMinister = GameImporter.get(XmlReader
//					.read(new File(
//							"/Users/obiwan/Desktop/export/priceminister.xml")));
			List<Game> siteSplitGames = GameImporter.get(XmlReader
					.read(new File(
							EXPORT_DIRECTORY + "/splitgames.xml")));
			List<Game> mergeList = GameMerger.merge(site2xmoinscher, sitePriceMinister.getGames(), siteSplitGames);
//			List<Game> mergeList = GameImporter.get(XmlReader
//					.read(new File(
//					"/Users/obiwan/Desktop/export/merged.xml")));

			XmlWriter.write(XmlGameExporter.export(mergeList), new File(
					EXPORT_DIRECTORY + "/merged.xml"));
//
			List<GameAnalysisReport> analyze = GameAnalyzer.analyze(mergeList);
//
			GameAnalysisReportExporter.export(analyze, new File(
					EXPORT_DIRECTORY));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
